﻿#region

using System;
using System.Collections.Generic;
using System.Security.Cryptography;
using System.Text;
using BusinessObjects;
using DataAccessLayer;

#endregion

namespace BusinessLogicLayer
{
    public static class PersonalCustomerBLL
    {
        /// <summary>
        ///     Get All personal customers
        /// </summary>
        /// <returns>All personal customers</returns>
        public static List<PersonalCustomer> GetAllPersonalCustomers()
        {
            return PersonalCustomerDAL.GetAllPersonalCustomers();
        }

        public static void RegisterPersonalCustomer(PersonalCustomer customer, User user)
        {
            user.Password = EncryptPassword(user.Password);
            PersonalCustomerDAL.RegisterPersonalCustomer(customer, user);
        }

        public static void UpdatePersonalCustomer(PersonalCustomer customer)
        {
            PersonalCustomerDAL.UpdatePersonalCustomer(customer);
        }

        public static void GetPersonalCustomerDetails(PersonalCustomer customer)
        {
            PersonalCustomerDAL.GetPersonalCustomerDetails(customer);
        }

        private static string EncryptPassword(string password)
        {
            var sha1 = new SHA1CryptoServiceProvider();
            var utf8 = new UTF8Encoding();
            var bytes = sha1.ComputeHash(utf8.GetBytes(password));
            return BitConverter.ToString(bytes).Replace("-", "");
        }
    }
}